#pragma once
#include <cocos2d.h>
#include <tcCommon/tc_common.h>
#include <vector>
#include "PropSprite.h"
#include "ChessmanSprite.h"

using namespace cocos2d;
using namespace std;

class GameLayer : public CCLayer
{
public:
	GameLayer();
	virtual ~GameLayer();
	static cocos2d::CCScene* scene();
	virtual bool init();
	LAYER_NODE_FUNC(GameLayer);
	//virtual void draw();
	virtual void update(ccTime dt);
	virtual void draw();

	virtual void onEnter();
	virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
	virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);

private:
	void load();
	void restart(tcType player);
	void restartCallback();
	void chessmenMovedToInitialPositionCallback();

	void createBackground();
	void createChessmenSprites();
	void createHinges();
	void createTurnMarkSprites();
	void createGameOverSprites();
	void createPropImages();
	void createPropButtons();

	void showPropImage(tcType propID);

	void updateGameState();
	void updateTurn();
	void updateChessmenSprites();
	void updatePropImages();

	vector<ChessmanSprite *> mChessmanSprites;
	CCSprite mTurnMarkSprites[2];
	CCSprite mGameOverSprites[2];
	CCSprite mGameOverStarSprite;
	CCSprite mPropImages[4];
	PropSprite mPropButtons[8];

	tcType mCurrentPlayer;
	bool mGameOverAnimationDone;
};

